package handler;

/**
 * A database Schema of the Users Table.  This allows
 * a row from the Table to taken from the database and
 * stored onto the active program.
 * 
 * @author David Hietpas
 */
public class User {
    private int id;
    private String user;
    private String password;
    private String email;
    private byte[] publicKey;
    
    public User() {}
    
    public User(String user, String password, String email, byte[] publicKey) {
        this.user = user;
        this.email = email;
        this.password = password;
        this.publicKey = publicKey;
    }
    
    public User(int id, String user, String password, String email, byte[] publicKey) {
        this.id = id;
        this.user = user;
        this.password = password;
        this.email = email;
        this.publicKey = publicKey;
    }
    
    /**
     * Returns Users email.
     * 
     * @return String email
     */
    public String getUserEmail() {
        return this.email;
    }
    
    /**
     * Returns Users Name.
     * 
     * @return String name
     */
    public String getUserName() {
        return this.user;
    }
    
    /**
     * Returns Users id.
     * 
     * @return int id
     */
    public int getId() {
        return this.id;
    }
    
    /**
     * Returns Users Public Key.
     * 
     * @return byte[] publicKey
     */
    public byte[] getPublicKey() {
        return this.publicKey;
    }
    
    /**
     * Returns Users Password
     * 
     * @return String password
     */
    public String getUserPassword() {
        return this.password;
    }
    
    /**
     * Sets Users email.
     * 
     * @param String email
     */
    public void setUserEmail(String email) {
        this.email = email;
    }

    /**
     * Sets Users name.
     * 
     * @param String name
     */
    public void setUser(String user) {
        this.user = user;
    }
    
    /**
     * Sets Users Password.
     * 
     * @param String password
     */
    public void setUserPassword(String password) {
        this.password = password;
    }
    
    /**
     * Sets Users Public Key.
     * 
     * @param byte[] publicKey
     */
    public void setPublicKey(byte[] publicKey) {
        this.publicKey = publicKey;
    }
    
    /**
     * If User exists in the Database, this method can be called
     * which will update it in the Database.
     * 
     */
    public void update() {
        DBHandler dbh = new DBHandler();
        dbh.updateUser(this);
    }

    /**
     * Returns a String Representation of the User Class.
     * 
     * @return String User
     */
    public String toString() {
        return "{" + id + " , " + user + " , " + new String (publicKey) + "}";
    }
    
}